# daca iti baga faze cu "no rule to make..." inseamna k ai gresit ceva prin _DEPS sau _SRCS
#.SUFFIXES: .c .cpp

SDIR = ./src/
IDIR = ./src/

INCLUDE = -I$(IDIR)

CC = g++

ifeq	($(DEBUG),1)
	DEFINES = -DDEBUG -D_DEBUG -DLINUX -O0 -ggdb
	ODIR = ./build/Linux/Debug
else
	DEFINES = -DLINUX -DNDEBUG -O2
	ODIR = ./build/Linux/Release
endif

CFLAGS = -Wall $(DEFINES) $(INCLUDE)

_SRCS = tinystr.cpp tinyxml.cpp tinyxmlerror.cpp tinyxmlparser.cpp
_OBJS = $(_SRCS:.cpp=.o)
_DEPS = tinystr.h tinyxml.h

SRCS = $(patsubst %,$(SDIR)/%,$(_SRCS))
OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

PRJ = $(ODIR)/libtinyxml.a


build:	build-path	all

all:	$(PRJ)

$(PRJ):	$(OBJS)
	ar rcs $@ $^

$(ODIR)/%.o:	$(SDIR)/%.cpp	$(DEPS)
	mkdir -p `dirname $@` 2>/dev/null
	$(CC) -c $< -o $@ $(CFLAGS)

build-path:	$(ODIR)

$(ODIR):
	mkdir -p $(ODIR)

.PHONY:	clean
	
clean:	clean-edits
	rm -fr $(ODIR)

clean-edits:
	#rm -fr $(find . -name *~)
	
rebuild:	clean	all

